package com.Controller;

import com.Service.FindBookService;
import com.Utils.RedisUtil;
import com.pojo.FindBook;
import com.pojo.FindRemark;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.sql.SQLException;
import java.util.List;
@Controller
@RequestMapping("/find")
public class FindBookController {
    @Autowired
    private FindBookService findBookService;

    @GetMapping("/booksByAuthor")
    @ResponseBody
    public List<FindBook> findBooksByAuthor(@RequestParam String inputValue, @RequestParam String elementId) throws SQLException {
        return findBookService.findBooksByAuthor(inputValue, elementId);
    }
    @GetMapping("/findBooksByIndex")
    public ModelAndView findBooksByIndex(@RequestParam String inputValue, @RequestParam String elementId) throws SQLException {
        ModelAndView modelAndView=new ModelAndView();
        List<FindBook>bookList=findBookService.findBooksByAuthor(inputValue,elementId);
        modelAndView.addObject("bookList",bookList);
        modelAndView.setViewName("sousuo");
        return  modelAndView;
    }
    @GetMapping("/findBookDetail")
    public ModelAndView findBookDetail(@RequestParam String bookId){
        ModelAndView modelAndView=new ModelAndView();
        FindBook book=findBookService.findBookDetail(bookId);
        List<FindBook> everybodyLikes = findBookService.findEverybodyLikes();
        modelAndView.addObject("everybodyLikes",everybodyLikes);
        modelAndView.addObject("book",book);
        modelAndView.setViewName("xiangqing");
        return  modelAndView;
    }
    @ResponseBody
    @GetMapping("/findBookCommentPage")
    public List<FindRemark> findBookCommentPage(String bookId, Integer pageNum,Integer pageSize,String currentTime){
        System.out.println(currentTime);
        return findBookService.findBookCommentPage(bookId,pageNum,pageSize,currentTime);
    }
    @ResponseBody
    @GetMapping("/findBookCommentCount")
    public Long findBookCommentCount(String bookId){
        return findBookService.findBookCommentCount(bookId);
    }
}
